<?php
require_once("../../../config.inc.php");
require_once("../../../app/_inc/include.php");
require_once("libraryFunction.php");

$errMsg = "";
if(isset($_REQUEST["reqtype"])){ 
	if($_REQUEST["reqtype"] == "save"){
		$errMsg .= libraryMod();
	}elseif($_REQUEST["reqtype"] == "delete"){
		$errMsg .= libraryDel();
	}
	$module = sxREQUEST("module");
	$layout = sxREQUEST("layout");
	$description = sxREQUEST("description");
	$note = sxREQUEST("note");
	$predefined_html = sxREQUEST("predefined_html");
}else{
	$library = "";
	$description = "";
	$note = "";
}
if(isset($_REQUEST["lib"]) && $_REQUEST["lib"] != ""){
	$sSQL = "SELECT * FROM library WHERE library='".$_REQUEST["lib"]."'";
	if($objSDAO->query($sSQL, "sel")){
		if($row = $objSDAO->fetch("sel")){
			$library = $row["library"];
			$description = $row["description"];
			$note = $row["note"];
		}else{
			$url = $_SESSION[USEROBJ]->getHistory(-1, true);
			serverRedir($url);
		}
	}else{
		$url = $_SESSION[USEROBJ]->getHistory(-1, true);
		serverRedir($url);
	}
}else{
	$url = $_SESSION[USEROBJ]->getHistory(-1, true);
	serverRedir($url);
}
//output HTML
$aOpz = array("tit2"=>_t("Visualizza libreria"));
echo(headerHTML($aOpz));
?>
<script language="JavaScript" type="text/javascript" src="../../_jsc/form.js"></script>  
<script language="JavaScript" type="text/javascript">
	function objFrmSave(){
		try{
			var objFrm = document.getElementById("objFrm");
			var objLib =  document.getElementById("library");
			var objDe =  document.getElementById("description");
			var objMessArea =  document.getElementById("messArea");
			var errMsg = "";
			if(objDe.value == ""){
				errMsg += "<?php echo _t("la description &egrave; obbligatoria.")?><br>";
				objDe.focus();
			}
			if(objLib.value == ""){
				errMsg += "<?php echo _t("il nome della libreria &egrave; obbligatorio.")?><br>";
				objFunc.focus();
			}
			if(errMsg == ""){
				objFrm.submit();
			}else{
				objMessArea.innerHTML = errMsg;
			}
		}catch(e){
			raiseError(e.description, "save new library");
		}			
	}
</script>
  
<?php
echo(bodyHTML($aOpz));
echo("<table width=\"100%\" cellpadding=\"03\" cellspacing=\"0\">\n<tr>\n<td>\n");
//form inserimento dati
echo("<form name=\"objFrm\" id=\"objFrm\" action=\"libraryView.php\" method=\"POST\" enctype=\"multipart/form-data\">");
echo("<input type=\"hidden\" name=\"reqtype\" id=\"reqtype\" value=\"save\">");
echo("<input type=\"hidden\" name=\"library\" id=\"library\" value=\"$library\">");
echo("<input type=\"hidden\" name=\"xsn\" value=\"".XSN."\">");

//output comandi
$aCmd = array(
					"fun"=>array("pag"=>"../func/functionList.php?lbr=$library",
										"title"=>_t("Lista funzioni"),
										"text"=>_t("funzioni"),
										"align"=>"L"
										),
					"del"=>array("pag"=>"javascript:confirmDelete()",
										"title"=>_t("Elimina la libreria"),
										"text"=>_t("elimina")
										),
					"mod"=>array("pag"=>"libraryMod.php?lib=$library",
										"title"=>_t("Modifica la libreria"),
										"text"=>_t("modifica")
										),
					"back"=>array("pag"=>$objUser->getHistory(-1,false),
										"title"=>$objUser->getHistoryText(-1),
										"text"=>$objUser->getHistoryText(-1)
										)
					);
echo(commandsHTML($aCmd));	
echo("<table class=\"tabl01\" width=\"100%\" cellpadding=\"3\" cellspacing=\"2\" border='0'>\n");
echo("<tr>" .
			"<td class=\"titl01\" colspan='2'>"._t("Libreria")."</td>" .
		"</tr>\n");
echo("<tr>" .
			"<td class=\"labl01\">"._t("libreria")." </td>" .
			"<td class=\"text01\">$library</td>" .
		"</tr>\n");
echo("<tr>" .
			"<td class=\"labl01\">"._t("description")." </td>" .
			"<td class=\"text01\">".sxHE($description)."</td>" .
		"</tr>\n");
echo("<tr>" .
			"<td class=\"labl01\">"._t("note")."</td>" .
			"<td class=\"text01\"><pre class=\"text01\">".sxWW(sxHE($note))."</pre></td>" .
		"</tr>\n");
echo("</table>");

echo(commandsHTML($aCmd));

echo("</form>");
echo("</td>\n</tr>\n</table>\n");
echo(footerHTML());
?>